package com.xyy.saas.payment.adpater.abchinaLoan.core.req;

import com.xyy.saas.payment.common.exception.PayBizException;
import com.xyy.saas.payment.cores.enums.ResultCodeEnum;
import com.xyy.saas.payment.util.DateUtil;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author wangzeqi
 */
@Data
@Accessors(chain = true)
public class OrderChangeDto {

    private String orderId;

    /**
     * 0-取消订单
     * 1-订单退货退款
     * 2-订单状态查询
     */
    private String chgType;

    /**
     * 每次退款唯一，若因网络等原因需重发，不改变流水号，仅退款时需输入
     */
    private String refundFlowNo;

    /**
     * 0-部分退款（退款金额小于订单金额），1-全额退款（退款金额等于订单金额），仅退款时需输入
     */
    private String refundType;

    /**
     * 退款金额
     */
    private BigDecimal refundAmt;

    /**
     * 交易时间
     */
    private String transTime = DateUtil.PATTERN_DATE.format(LocalDateTime.now());

    public static OrderChangeDto mock() {
        OrderChangeDto orderChangeDto = new OrderChangeDto();
        orderChangeDto.setOrderId("1");
        orderChangeDto.setChgType("2");
        //orderChangeDto.setRefundFlowNo();
        //orderChangeDto.setRefundType();
        //orderChangeDto.setRefundAmt();
        orderChangeDto.setTransTime(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()));
        return orderChangeDto;
    }

    public void checkParam() {
        if (StringUtils.isBlank(orderId) || StringUtils.isBlank(chgType)) {
            throw new PayBizException(ResultCodeEnum.PARAM_ERROR);
        }
    }

}
